<template>
  <div>
    <PageTemplate>
      <div slot="content">
        <PageEditCollapse :is-search="false" :default-collapse="true">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 200px;">{{$t('cm.baseinfo')}}</div>
          </div>
          <div>
            <el-form
              :model="dataDictGroup"
              label-position="right"
              label-width="150px"
              class="page-edit-colllapse-form"
              :rules="rules"
              ref="dataDictGroup"
            >
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('sys.dict_group_name')" prop="dictGroupName">
                    <el-input v-model="dataDictGroup.dictGroupName"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <el-form-item :label="$t('sys.dict_group_key')" prop="dictGroupKey">
                    <el-input v-model="dataDictGroup.dictGroupKey"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="12">
                  <el-form-item :label="$t('sys.system_data_dict')" prop="systemDataDict">
                    <el-radio-group v-model="dataDictGroup.systemDataDict">
                      <el-radio v-for="(item, index) in systemDataDicts"  :key="index" :label="item.value">{{$t(item.label)}}</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                </el-col>
              </el-row>
            </el-form>
          </div>
        </PageEditCollapse>
        <el-row class="row-empty-10"></el-row>
        <el-row>
          <el-button type="primary" @click="submitForm('dataDictGroup')" :loading="submiting" class="loading-submiting">
            {{$t('cm.commit')}}
          </el-button>
          <el-button type="primary" @click="toList">
            {{$t('cm.return')}}
          </el-button>
        </el-row>
      </div>
    </PageTemplate>
  </div>
</template>

<script>
import { ALERT } from '@/utils/responseHandle'
import * as Constant from '@/utils/constant'
import PageTemplate from '@/components/common/PageTemplate'
import PageEditCollapse from '@/components/common/PageEditCollapse'
import HasBtn from '@/mixins/HasBtn'
import { mapState } from 'vuex'
import {COMMON} from '@/utils/commonUtil'
import sys_manage from '@/api/sys_manage'
import Submiting from '@/mixins/Submiting'
export default {
  components: {
    PageTemplate, PageEditCollapse
  },
  mixins: [Submiting],
  data () {
    return {
      dataDictGroup: {
        id: null,
        dictGroupName: null,
        dictGroupKey: null,
        systemDataDict: Constant.SYSTEM_DATA_DICT_Y.value,
        isValid: 'Y'
      },
      rules: {
        dictGroupName: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        dictGroupKey: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        systemDataDict: [
          { required: true, message: '必填项', trigger: 'change' }
        ]
      },
      systemDataDicts: [Constant.SYSTEM_DATA_DICT_Y, Constant.SYSTEM_DATA_DICT_N]
    }
  },
  created () {
    if (this.$router.history.current.params.id !== Constant.NEW_PARAMS) {
      this.sysDictGroupGet(this.$router.history.current.params.id)
    }
  },
  methods: {
    sysDictGroupGet (id) { // 错误的接口
      sys_manage.sysDictGroupGet({dictGroupKey: id}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          this.dataDictGroup = result.data
        } else {
          ALERT.error(result.msg)
        }
      })
    },
    submitForm (formName) {
      this.openSubmiting()
      this.$refs[formName].validate((valid, error) => {
        if (valid) {
          sys_manage.sysDictGroupSave(this.dataDictGroup, result => {
            if (result.code === Constant.RT_SUCCESS) {
              ALERT.success(result.msg)
              this.toList()
            } else {
              // _this.$t('cm.tips')
              ALERT.error(result.msg)
            }
            this.closeSubmiting()
          })
        } else {
          this.closeSubmiting()
          return false
        }
      })
      
    },
    toList () {
      COMMON.routerTo(Constant.ROUTE_SYS_DICT_GROUP.index, this.$router)
    }
  },
  mounted () {
  },
  computed: {
  }
}
</script>

<style lang="scss">
</style>
